<template>
  <div class="printForm">
    <table class="printTable">
      <tr>
        <td class="tit">{{ $t('项目名称') }}</td>
        <td>{{ form.dealName }}</td>
        <td class="tit">{{ companyLabel }}</td>
        <td>
          {{ form.companyName }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('申请标题') }}</td>
        <td colspan="3">{{ form.actTitle }}</td>
      </tr>
      <tr>
        <td class="tit">{{ $t('项目负责人') }}</td>
        <td>{{ form.personChargeName }}</td>
        <td class="tit">{{ $t('项目类型') }}</td>
        <td>
          <dictSelect
            v-model="form.dealType"
            dictionary="deal_type"
          />
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('预计投资时间') }}</td>
        <td>{{ parseTime(form.dateInvestmentEstimate) }}</td>
        <td class="tit">{{ $t('预计投资金额') }}{{ $t('金额单位') }}</td>
        <td>
          {{ moneyFormat(form.amountInvestmentEstimate, 'w') }}
        </td>
      </tr>
      <template v-if="form.dealType === 'equity'">
        <tr>
          <!--债权投资字段-->
          <td class="tit">{{ $t('投资轮次') }}</td>
          <td>
            <dictSelect
              v-model="form.dealWfStorageEquity.round"
              dictionary="rounds_investment"
            />
          </td>
          <td class="tit">{{ $t('公司总股数/注册资本') }}</td>
          <td>
            {{ moneyFormat(form.dealWfStorageEquity.totalShare) }}
          </td>
        </tr>
        <tr>
          <!--债权投资字段-->
          <td class="tit">{{ $t('投前估值') }}{{ $t('金额单位') }}</td>
          <td>
            {{ moneyFormat(form.dealWfStorageEquity.valuationBeforeInvestment, 'w') }}
          </td>
          <td class="tit">{{ $t('退出计划') }}</td>
          <td>
            {{ form.dealWfStorageEquity.planExit }}
          </td>
        </tr>
      </template>
      <template v-if="form.dealType === 'debt'">
        <tr>
          <!--股权投资字段-->
          <td class="tit">{{ $t('期限') }}</td>
          <td>{{ form.dealWfStorageDebt.period }}</td>
          <td class="tit">{{ $t('预计年化收益率(%)') }}</td>
          <td>
            {{ form.dealWfStorageDebt.incomeRate }}
          </td>
        </tr>
        <tr>
          <!--股权投资字段-->
          <td class="tit">{{ $t('发行主体') }}</td>
          <td>{{ form.dealWfStorageDebt.issued.companyName }}</td>
          <td class="tit">{{ $t('发行主体评级') }}</td>
          <td>
            <dictSelect
              v-model="form.dealWfStorageDebt.issuedRating"
              dictionary="debt_rating"
            />
          </td>
        </tr>
        <tr>
          <!--股权投资字段-->
          <td class="tit">{{ $t('融资主体评级') }}</td>
          <td>
            <dictSelect
              v-model="form.dealWfStorageDebt.financingRating"
              dictionary="debt_rating"
            />
          </td>
          <td class="tit">{{ $t('债项评级') }}</td>
          <td>
            <dictSelect
              v-model="form.dealWfStorageDebt.debtRating"
              dictionary="debt_rating"
            />
          </td>
        </tr>
        <tr>
          <!--股权投资字段-->
          <td class="tit">{{ $t('增信措施') }}</td>
          <td>{{ form.dealWfStorageDebt.creditMeasures }}</td>
          <td class="tit">{{ $t('增信描述') }}</td>
          <td>
            {{ form.dealWfStorageDebt.creditDescription }}
          </td>
        </tr>
      </template>
      <template v-if="form.dealType === 'bf'">
        <!-- 参股基金字段 -->
        <tr>
          <td class="tit">{{ $t('基金认缴规模') }}{{ $t('金额单位') }}</td>
          <td>
            {{ moneyFormat(form.dealWfBfBase.subscribeScale, 'w') }}
          </td>
          <td class="tit">{{ $t('基金实缴规模') }}{{ $t('金额单位') }}</td>
          <td>
            {{ moneyFormat(form.dealWfBfBase.paidInScale, 'w') }}
          </td>
        </tr>
        <tr>
          <td class="tit">{{ $t('基金投资类型') }}</td>
          <td>
            <dictSelect
              v-model="form.dealWfBfBase.investType"
              dictionary="fund_invest_type"
            />
          </td>
          <td class="tit">{{ $t('基金类型') }}</td>
          <td>
            <dictSelect
              v-model="form.dealWfBfBase.fundType"
              dictionary="fund_type"
            />
          </td>
        </tr>
        <tr>
          <td class="tit">{{ $t('基金阶段') }}</td>
          <td>
            <dictSelect
              v-model="form.dealWfBfBase.fundStage"
              dictionary="fund_phase"
            />
          </td>
          <td class="tit">{{ $t('基金注册成立日') }}</td>
          <td>
            {{ parseTime(form.dealWfBfBase.fundSetTime) }}
          </td>
        </tr>
        <tr>
          <td class="tit">{{ $t('管理公司') }}</td>
          <td>
            {{ form.dealWfBfBase.manageCompanyName }}
          </td>
          <td class="tit">{{ $t('管理公司认缴比例(%)') }}</td>
          <td>
            {{ form.dealWfBfBase.manageSubscribeRatio }}
          </td>
        </tr>
      </template>
      <tr>
        <td class="tit">{{ $t('项目来源') }}</td>
        <td colspan="3">
          {{ form.dealSource }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('项目简介') }}</td>
        <td colspan="3">
          {{ form.dealIntroduction }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('项目主要优点') }}</td>
        <td colspan="3">
          {{ form.dealStrongPoint }}
        </td>
      </tr>
      <tr>
        <td class="tit">{{ $t('项目主要顾虑') }}</td>
        <td colspan="3">
          {{ form.dealScruple }}
        </td>
      </tr>
    </table>
    <!-- 附件列表 -->
    <FileView :list.sync="form.fileList" data-type="deal_process" :business-id="form.dealId" :btn-show="!otherBtnHide" />

  </div>
</template>

<script>
import {
  saveDealWfStorage,
  getDealWfStorage,
  getByWfNodeId
} from '@/api/deal/form/dealWfStorage'
export default {
  data() {
    return {
      // 表单参数
      form: {},
      companyLabel: ''
    }
  },
  watch: {
    'form.dealType': {
      handler(val) {
        if (val === 'equity') {
          this.companyLabel = this.$t('公司名称')
        } else if (val === 'debt') {
          this.companyLabel = this.$t('融资方名称')
        } else if (val === 'bf') {
          this.companyLabel = this.$t('基金名称')
        }
      }
    }
  },
  created() {
    this.$bus.$emit('async_done')
  },
  methods: {
    // 初始化数据
    init(data) {
      this.loading = true
      if (data != null && data.id !== undefined) {
        getDealWfStorage(data.id).then(response => {
          this.form = response.data
          this.loading = false
        })
      } else {
        getByWfNodeId(data.wfNodeId).then(response => {
          this.form = response.data
          if (data !== null) {
            this.form.fileList = data.fileList
            this.form.actTitle = data.actTitle
          }
          this.loading = false
        })
      }
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        dealId: undefined,
        dealName: undefined,
        actTitle: undefined,
        companyId: undefined,
        personCharge: undefined,
        dealType: undefined,
        industryFocus: undefined,
        dealSource: undefined,
        dateInvestmentEstimate: undefined,
        amountInvestmentEstimate: undefined,
        dealIntroduction: undefined,
        dealStrongPoint: undefined,
        dealScruple: undefined,
        dealWfStorageEquity: {}, // 股权项目字段
        // 债权项目字段
        dealWfStorageDebt: {
          issued: {
            id: undefined, // 发行主体ID
            companyName: undefined // 发行主体名称
          }
        },
        fileList: []
      }
      this.resetForm('form')
    },
    // 取消按钮
    cancel() {
      this.$parent.$parent.formOpen = false
      this.$parent.$parent.reset()
    },
    /** 提交按钮 */
    submitForm: function() {
      return new Promise((resolve, reject) => {
        this.$refs['form'].validate(valid => {
          if (valid) {
            this.loading = true
            saveDealWfStorage(this.form)
              .then(response => {
                if (response.code === 200) {
                  this.msgSuccess(this.$t('保存成功'))
                  this.loading = false
                  resolve(response.data.id)
                } else {
                  this.msgError(response.msg)
                  this.loading = false
                  reject(response)
                }
              })
              .catch(() => {
                this.loading = false
              })
          } else {
            reject()
          }
        })
      })
    }
  }
}
</script>
